class UnsupportedPackagesPlugin(computerjanitor.Plugin):
'''Plugin to find packages no longer supported by Canonical.
An unsupported package is one that is no longer available in the
archive.
Unfortunately, this heuristic is unable to treat packages installed
manually (via dpkg), or from sources (such as PPAs) that are no longer
in sources.list.
'''
description = _('Package is no longer supported: it is no longer in the package archive. (It may also have been installed from an unofficial archive that is no longer available. In that case you may want to keep it.)')
basenames = [
'linux-image',
'linux-headers',
'linux-image-debug',
'linux-ubuntu-modules',
'linux-header-lum',
'linux-backport-modules',
'linux-header-lbm',
'linux-restricted-modules']
def __init__(self):
self.uname = os.uname()[2]
def is_current_kernel(self, pkg):
"""Is pkg the currently running kernel or a related package?
We don't want to remove the currently running kernel. The
kernel packages have names that start with the strings in
self.basenames, and end with the 'release' string from
os.uname.
"""
for base in self.basenames:
if pkg.name == '%s-%s' % (base, self.uname):
return True
return False
def installed_deps(self, pkg):
'''Return set of names of installed dependencies of a package.
Only immediate dependencies, dependency graph is not traversed
deeply.
'''
result = set()
for dep in pkg.installedDependencies:
for or_dep in dep.or_dependencies:
result.add(or_dep.name)
return result
def has_installed_rdepends(self, cache, pkg):
'''Does a package have any installed reverse dependencies?'''
installed = _[1]
for x in installed:
if pkg.name in self.installed_deps(x):
return True
return False
def is_supported(self, pkg):
'''Is a package supported?'''
if not pkg.isInstalled:
return True
if pkg.installedDownloadable or pkg.candidateDownloadable:
return True
if len(pkg._pkg.VersionList) > 1:
return True
if self.is_current_kernel(pkg):
return True
return False
def get_cruft(self):
for pkg in self.app.apt_cache:
if not self.is_supported(pkg):
if not self.has_installed_rdepends(self.app.apt_cache, pkg):